package com.cityfood.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cityfood.mapper.CfProductDetailMapper;
import com.cityfood.pojo.CfProductDetail;
import com.cityfood.pojo.CfProductDetailExample;
import com.cityfood.pojo.CfProductDetailExample.Criteria;
import com.cityfood.service.ProductDetailService;

@Service
public class ProductDetailServiceImpl implements ProductDetailService {

	@Autowired
	private CfProductDetailMapper productDetailMapper;
	
	@Override
	public CfProductDetail getProductDetailByProductId(Integer productId) {
		CfProductDetail detail = new CfProductDetail();
		CfProductDetailExample example = new CfProductDetailExample();
		Criteria criteria = example.createCriteria();
		criteria.andProductIdEqualTo(productId);
		List<CfProductDetail> list = productDetailMapper.selectByExampleWithBLOBs(example);
		if (list.size()>0) {
			detail=list.get(0);
			return detail;
		}
		return detail;
	}

	@Override
	public int insertProductDetail(CfProductDetail detail) {
		detail.setCreateTime(new Date());
		detail.setUpdateTime(new Date());
		int i = productDetailMapper.insertSelective(detail);
		return i;
	}

	@Override
	public int updateProductDetail(CfProductDetail detail) {
		detail.setUpdateTime(new Date());
		int i = productDetailMapper.updateByPrimaryKeySelective(detail);
		return i;
	}

	@Override
	public int deleteProductDetail(CfProductDetail detail) {
		detail.setUpdateTime(new Date());
		detail.setIsdisplay((byte)0);
		int i = productDetailMapper.updateByPrimaryKeySelective(detail);
		return i;
	}

}
